package com.ruoyi.web.controller.kyhs;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.kysh.entity.TableInf;
import com.ruoyi.system.kysh.mapper.TableInfMapper;
import com.ruoyi.system.kysh.service.TableInfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api("获取部门")
@RestController
@RequestMapping("/kyhs/table-inf")
public class TableInfController {

    @Autowired
    private TableInfService tableInfService;

    @Autowired
    private TableInfMapper tableInfMapper;

    @ApiOperation("获取部门列表")
    @GetMapping("/select-all")
    public AjaxResult getTable(){

        LambdaQueryWrapper<TableInf> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.ne(TableInf::getParentId,-1);

        List<TableInf> collect = tableInfService.list(lambdaQueryWrapper).stream().peek((it) -> {
            it.setDeptRank(tableInfMapper.getDeptRank(it.getParentId()).split(",").length);
        }).collect(Collectors.toList());

        return AjaxResult.success("操作成功",collect);
    }


}
